*Coding missing values*
mvdecode Q17 Q18 Q20 Q21A Q21B Q21C Q21D Q21E Q21F Q21G Q21H Q21I Q21J Q21K Q21L, mv(3=.)
mvdecode Q2 Q22A Q22B Q22C Q22D Q22E Q22F, mv(4=.)
mvdecode Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13, mv(7=.)
mvdecode Q23 Q27A Q27B Q27C Q27D Q27E Q27F Q27G Q27H Q32, mv(6=.)
mvdecode Q14 Q15 Q16 Q29, mv(9=.)
mvdecode Q34, mv(10=.)
mvdecode Q26A JobSector, mv(11=.)
mvdecode Q19A Q19B Q19C Q19D Q19E Q19F Q24A Q24B Q24C Q24D Q24E Q25 Q28 TotalMonthlyIncome, mv(5=.)

*Recoding dichotomous variables to be 0-1, and inverting yes/no variables*
tab Q2
replace Q2 = Q2 - 1
label define A 0 "Computer" 1 "Mobile Device"
label values Q2 A
tab Q2

tab Q17
replace Q17 = (Q17 * - 1) + 2
label define B 0 "No" 1 "Yes"
label values Q17 B
tab Q17

tab Q18
replace Q18 = (Q18 * - 1) + 2
label values Q18 B
tab Q18

tab Q20
replace Q20 = (Q20 * - 1) + 2
label values Q20 B
tab Q20

tab Q21A
replace Q21A = (Q21A * - 1) + 2
label values Q21A B
tab Q21A

tab Q21B
replace Q21B = (Q21B * - 1) + 2
label values Q21B B
tab Q21B

tab Q21C
replace Q21C = (Q21C * - 1) + 2
label values Q21C B
tab Q21C

tab Q21D
replace Q21D = (Q21D * - 1) + 2
label values Q21D B
tab Q21D

tab Q21E
replace Q21E = (Q21E * - 1) + 2
label values Q21E B
tab Q21E

tab Q21F
replace Q21F = (Q21F * - 1) + 2
label values Q21F B
tab Q21F

tab Q21G
replace Q21G = (Q21G * - 1) + 2
label values Q21G B
tab Q21G

tab Q21H
replace Q21H = (Q21H * - 1) + 2
label values Q21H B
tab Q21H

tab Q21I
replace Q21I = (Q21I * - 1) + 2
label values Q21I B
tab Q21I

tab Q21J
replace Q21J = (Q21J * - 1) + 2
label values Q21J B
tab Q21J

tab Q21K
replace Q21K = (Q21K * - 1) + 2
label values Q21K B
tab Q21K

tab Q21L
replace Q21L = (Q21L * - 1) + 2
label values Q21L B
tab Q21L*Multiple Imputation-Modeled using all variables with no missing values in the imputation model*
mi set flong

mi register imputed Q5 Q6 Q7 Q9 Q10 Q11 Q12 Q14 Q15 Q16 Q18 Q19A Q19B Q19C Q19D Q19E Q21C Q21F Q21G Q21I Q21J Q21K Q25 Q27A Q27B Q27C Q27D Q27E ///
Q27F Q27G Q27H Q28 Q29 Q31 Q32 Q33 Q34 Q35

mi impute mvn Q5 Q6 Q7 Q9 Q10 Q11 Q12 Q14 Q15 Q16 Q18 Q19A Q19B Q19C Q19D Q19E Q21C Q21F Q21G Q21I Q21J Q21K Q25 Q27A Q27B Q27C Q27D Q27E ///
Q27F Q27G Q27H Q28 Q29 Q31 Q32 Q33 Q34 Q35, add(5)

*Replication Script Political Behavior*
*Media Use Measures****************************************************************************************************************************************
*Political Internet Media Use Index*
alpha Q5 Q6 Q7 if _mi_m == 0
gen pol_int_use = (Q5 + Q6 + Q7) * (-1)
foreach v of var pol_int_use {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ pol_int_use

*Political Traditional Media Use Index*
alpha Q14 Q15 Q16 if _mi_m == 0
gen pol_trad_use = Q14 + Q15 + Q16 
foreach v of var pol_trad_use {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ pol_trad_use

*Media Trust Measures********************************************************************************************************************************
*Traditional Media Trust*
alpha Q19A Q19B Q19C if _mi_m == 0
gen trad_media_trust = (Q19A + Q19B + Q19C) * (-1)
foreach v of var trad_media_trust {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ trad_media_trust

*Internet Media Trust*
gen Q19D_rc = (Q19D) * (-1)
foreach v of var Q19D_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q19D_rc

gen Q19E_rc = (Q19E) * (-1)
foreach v of var Q19E_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q19E_rc

alpha Q19D_rc Q19E_rc Q18 if _mi_m == 0
gen internet_media_trust = (Q19D_rc + Q19E_rc + Q18)
foreach v of var internet_media_trust {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ internet_media_trust


*Dependent Variables**************************************************************************************************************************************

*Non-Traditional Participation Index*
alpha Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m == 0
gen non_trad_part = Q21C + Q21F + Q21G + Q21I + Q21J + Q21K
foreach v of var non_trad_part {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ non_trad_part

*Factor score for Non-Trad Participation
*Factor Analyses (using Maximum Liklihood)

*Looks like the all load on the same factor, but do not scale that well together, play with 
factor Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m ==1, factors(1) ml
rotate

factor Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m ==2, factors(1) ml
rotate

factor Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m ==3, factors(1) ml
rotate

factor Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m ==4, factors(1) ml 
rotate

factor Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m ==5, factors(1) ml
rotate


*Factor scores-factor scores generated using regression method)*
factor Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m ==1, factors(1) ml
rotate
predict f1 if _mi_m ==1

factor Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m ==2, factors(1) ml 
rotate
predict f2 if _mi_m ==2

factor Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m ==3, factors(1) ml 
rotate
predict f3 if _mi_m ==3

factor Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m ==4, factors(1) ml 
rotate
predict f4 if _mi_m ==4

factor Q21C Q21F Q21G Q21I Q21J Q21K if _mi_m ==5, factors(1) ml 
rotate
predict f5 if _mi_m ==5

replace f1 = 0 if f1 == .
replace f2 = 0 if f2 == .
replace f3 = 0 if f3 == .
replace f4 = 0 if f4 == .
replace f5 = 0 if f5 == .

*Contruction of Internet Use Factor Score (all 4 items)*
gen protest_factor = (f1 + f2 + f3 + f4 + f5)/5 
foreach v of var protest_factor {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ protest_factor

*Attitude about democracy Index*
gen Q25_rc  = (Q25) * (-1)
foreach v of var Q25_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q25_rc

gen Q27A_rc = (Q27A) * (-1)
foreach v of var Q27A_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q27A_rc

gen Q27B_rc  = (Q27B) * (-1) 
foreach v of var Q27B_rc  {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q27B_rc 

gen Q27C_rc = (Q27C) * (-1)
foreach v of var Q27C_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q27C_rc

gen Q27D_rc = (Q27D) * (-1) 
foreach v of var Q27D_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q27D_rc

gen Q27E_rc = (Q27E) * (-1) 
foreach v of var Q27E_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q27E_rc

gen Q27F_rc = (Q27F) * (-1)
foreach v of var Q27F_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q27F_rc

gen Q27G_rc = (Q27G) * (-1)
foreach v of var Q27G_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q27G_rc

gen Q27H_rc = (Q27H) * (-1) 
foreach v of var Q27H_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q27H_rc

gen Q28_rc = (Q28) * (-1)
foreach v of var Q28_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q28_rc

alpha Q25_rc Q27A_rc Q27B_rc Q27C_rc Q27D_rc Q27E_rc Q27F_rc Q27G_rc Q27H_rc Q28_rc if _mi_m == 0
gen democracy = (Q25_rc + Q27A_rc + Q27B_rc + Q27C_rc + Q27D_rc + Q27E_rc + Q27F_rc + Q27G_rc + Q27H_rc + Q28_rc)
foreach v of var democracy {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ democracy

*Control Variables**********************************************************************************************************************************************
*Urbanicity*
gen urbanicity = Q29 
foreach v of var urbanicity {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ urbanicity

*Gender*
tab Q31
gen female = 1 if Q31 == 2
replace female = 0 if Q31 ==1
tab female


*Age*
gen age = Q33 
foreach v of var age {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ age

*SES*********
*Household Income*
gen Q32_rc = Q32 
foreach v of var Q32_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ Q32_rc

*Education*
tab Q34 if _mi_m ==5
gen Q34_rc = Q34 
foreach v of var Q34_rc {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
tab Q34_rc if _mi_m ==5

*SES*
gen ses = Q32_rc + Q34_rc
foreach v of var ses {
su `v', meanonly
replace `v' = (`v' - r(min))/(r(max) - r(min))
}
summ ses

*Malay dummy*
gen malay = 1 if Q35 == 1
replace malay = 0 if Q35 > 1


*Analysis******************************************************************************************************************************************************
*Table 1- Distribution Trust Items*
tab Q18 if _mi_m == 0
tab Q19A if _mi_m == 0
tab Q19B if _mi_m == 0
tab Q19C if _mi_m == 0
tab Q19D if _mi_m == 0
tab Q19E if _mi_m == 0


*CEM for Table 2*

xtile pol_trad_use_d = pol_trad_use, n(2)
xtile pol_int_use_d = pol_int_use, n(2)
xtile internet_media_trust_d=internet_media_trust, n(2)
xtile trad_media_trust_d = trad_media_trust, n(2)
xtile urbanicity_d = urbanicity, n(2)
xtile ses_d = ses, n(2)
xtile age_d = age, n(2)
xtile Q1_d = Q1, n(2)

*For L1 statistic and percentages of matched cases - Table 2 top*
imb internet_media_trust_d urbanicity_d female ses_d age_d malay, treatment (trad_media_trust_d) impvar(_mi_m)
cem internet_media_trust_d urbanicity_d female ses_d age_d malay, treatment (trad_media_trust_d) impvar(_mi_m)

rename cem_weights cem_weights_trad_media_trust_d

*For L1 statistic and percentages of matched cases - Table 2 top*
imb trad_media_trust_d urbanicity_d female ses_d age_d malay, treatment (internet_media_trust_d) impvar(_mi_m)
cem trad_media_trust_d urbanicity_d female ses_d age_d malay, treatment (internet_media_trust_d) impvar(_mi_m)

rename cem_weights cem_weights_internet_media


*Table 2 - The more you trust media, the more you consume from it*
mibeta pol_trad_use internet_media_trust trad_media_trust urbanicity female ses age malay
regress pol_trad_use internet_media_trust trad_media_trust urbanicity female ses age malay if _mi_m == 0
mi estimate: regress pol_trad_use internet_media_trust trad_media_trust urbanicity female ses age malay [iweight=cem_weights_trad_media_trust_d]
mibeta pol_int_use internet_media_trust trad_media_trust urbanicity female ses age malay
regress pol_int_use internet_media_trust trad_media_trust urbanicity female ses age malay if _mi_m == 0
mi estimate: regress pol_int_use internet_media_trust trad_media_trust urbanicity female ses age malay [iweight=cem_weights_internet_media]

*Cem for Table 3*

*For L1 statistic and percentages of matched cases - Table 3 top - Int Use Treatment*
imb pol_trad_use_d urbanicity_d female ses_d age_d malay, treatment (pol_int_use_d) impvar(_mi_m)
cem pol_trad_use_d urbanicity_d female ses_d age_d malay, treatment (pol_int_use_d) impvar(_mi_m)

rename cem_weights cem_weights_pol_int_use

*For L1 statistic and percentages of matched cases - Table 3 top - Trad Use Treatment*
imb pol_int_use_d urbanicity_d female ses_d age_d malay, treatment (pol_trad_use_d) impvar(_mi_m)
cem pol_int_use_d urbanicity_d female ses_d age_d malay, treatment (pol_trad_use_d) impvar(_mi_m)

rename cem_weights cem_weights_pol_trad_use

*For L1 statistic and percentages of matched cases - Table 3 bottom - Int Trust Treatment*
imb trad_media_trust_d pol_trad_use_d urbanicity_d female ses_d age_d malay, treatment (internet_media_trust_d) impvar(_mi_m)
cem trad_media_trust_d pol_trad_use_d urbanicity_d female ses_d age_d malay, treatment (internet_media_trust_d) impvar(_mi_m)

rename cem_weights cem_weights_internet_media_trust

*For L1 statistic and percentages of matched cases - Table 3 bottom - Trad Trust Treatment*
imb internet_media_trust_d pol_trad_use_d urbanicity_d female ses_d age_d malay, treatment (trad_media_trust_d) impvar(_mi_m)
cem internet_media_trust_d pol_trad_use_d urbanicity_d female ses_d age_d malay, treatment (trad_media_trust_d) impvar(_mi_m)

rename cem_weights cem_weights_trad_media_trust

*Table 3 - It's Trust that Matters More than Exposure*
mibeta democracy pol_int_use pol_trad_use urbanicity female ses age malay
regress democracy pol_int_use pol_trad_use urbanicity female ses age malay if _mi_m == 0
mi estimate: regress democracy pol_int_use pol_trad_use urbanicity female ses age malay [iweight=cem_weights_pol_int_use]
mi estimate: regress democracy pol_int_use pol_trad_use urbanicity female ses age malay [iweight=cem_weights_pol_trad_use]

mibeta democracy internet_media_trust trad_media_trust pol_int_use pol_trad_use urbanicity female ses age malay
regress democracy internet_media_trust trad_media_trust pol_int_use pol_trad_use urbanicity female ses age malay if _mi_m == 0
mi estimate: regress democracy internet_media_trust trad_media_trust pol_int_use pol_trad_use urbanicity female ses age malay [iweight=cem_weights_internet_media_trust]
mi estimate: regress democracy internet_media_trust trad_media_trust pol_int_use pol_trad_use urbanicity female ses age malay [iweight=cem_weights_trad_media_trust]


*Table 4 - Trust and Protest - Trust Mediates inclination to protest*
mibeta non_trad_part internet_media_trust trad_media_trust pol_int_use pol_trad_use urbanicity female ses age malay
regress non_trad_part internet_media_trust trad_media_trust pol_int_use pol_trad_use urbanicity female ses age malay if _mi_m == 0
mi estimate: regress non_trad_part internet_media_trust trad_media_trust pol_int_use pol_trad_use urbanicity female ses age malay [iweight=cem_weights_internet_media_trust]
mi estimate: regress non_trad_part internet_media_trust trad_media_trust pol_int_use pol_trad_use urbanicity female ses age malay [iweight=cem_weights_trad_media_trust]

mibeta non_trad_part c.internet_media_trust##c.pol_int_use trad_media_trust pol_trad_use urbanicity female ses age malay
regress non_trad_part c.internet_media_trust##c.pol_int_use trad_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 0
mi estimate: regress non_trad_part c.internet_media_trust##c.pol_int_use trad_media_trust pol_trad_use urbanicity female ses age malay [iweight=cem_weights_internet_media_trust]


regress non_trad_part c.internet_media_trust##c.pol_int_use trad_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 1
regress non_trad_part c.internet_media_trust##c.pol_int_use trad_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 2
regress non_trad_part c.internet_media_trust##c.pol_int_use trad_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 3
regress non_trad_part c.internet_media_trust##c.pol_int_use trad_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 4
regress non_trad_part c.internet_media_trust##c.pol_int_use trad_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 5
margins if _mi_m==5, at(pol_int_use=(0 1) internet_media_trust=(0(.5)1)) 
marginsplot, x(pol_int_use) recast(line) recastci(rarea) xlabel(0(.5)1)

mibeta non_trad_part c.trad_media_trust##c.pol_int_use internet_media_trust pol_trad_use urbanicity female ses age malay
regress non_trad_part c.trad_media_trust##c.pol_int_use internet_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 0
mi estimate: regress non_trad_part c.trad_media_trust##c.pol_int_use internet_media_trust pol_trad_use urbanicity female ses age malay [iweight=cem_weights_trad_media_trust]

regress non_trad_part c.trad_media_trust##c.pol_int_use internet_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 1
regress non_trad_part c.trad_media_trust##c.pol_int_use internet_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 2
regress non_trad_part c.trad_media_trust##c.pol_int_use internet_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 3
regress non_trad_part c.trad_media_trust##c.pol_int_use internet_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 4
regress non_trad_part c.trad_media_trust##c.pol_int_use internet_media_trust pol_trad_use urbanicity female ses age malay if _mi_m == 5
margins if _mi_m==5, at(pol_int_use=(0 1) trad_media_trust=(0(.5)1)) 
marginsplot, x(pol_int_use) recast(line) recastci(rarea) xlabel(0(.5)1)

graph combine a b

*Footnote with factor score DV instead of index
mibeta protest_factor internet_media_trust trad_media_trust pol_int_use pol_trad_use urbanicity female ses age malay
mibeta protest_factor c.internet_media_trust##c.pol_int_use trad_media_trust pol_trad_use urbanicity female ses age malay
mibeta protest_factor c.trad_media_trust##c.pol_int_use internet_media_trust pol_trad_use urbanicity female ses age malay
